package jp.seraph.same.model;

import java.util.HashMap;
import java.util.Map;

import jp.seraph.jsade.math.Angle;
import jp.seraph.jsade.model.JointIdentifier;
import jp.seraph.jsade.model.JointIdentifierContainer;
import jp.seraph.jspf.pose.DefaultPose;
import jp.seraph.jspf.pose.Pose;

public class DefaultPoseModel extends AbstractViewModel implements PoseModel {
    public DefaultPoseModel(String aName, JointIdentifierContainer aIdContainer) {
        super(aName);
        mAngleMap = new HashMap<JointIdentifier, Angle>();

        for (JointIdentifier tId : aIdContainer) {
            mAngleMap.put(tId, Angle.ZERO);
        }
    }

    private Map<JointIdentifier, Angle> mAngleMap;

    public Angle getAngle(JointIdentifier aId) {
        return mAngleMap.get(aId);
    }

    public void setAngle(JointIdentifier aId, Angle aAngle) {
        if (aAngle.equals(mAngleMap.get(aId)))
            return;

        mAngleMap.put(aId, aAngle);
        fireChangedEvent();
    }

    public Pose toPose() {
        DefaultPose tPose = new DefaultPose();

        for (JointIdentifier tId : mAngleMap.keySet()) {
            tPose.setJointAngle(tId, mAngleMap.get(tId));
        }

        return tPose;
    }
}
